var uid = getParameter("uid");
var now = new Date();
$(function() {
	charts(now);
});

function charts(now) {
	var urlStr = serverPath + "/app/doctor/diabetes/pressureView.do";
	
	var jsonStr = 
	    '{'+
	    '	   "requestid":"",'+
	    '	   "requestsource":"diabetes",'+
	    '	   "sessionid":"",'+
	    '	   "uid":"'+uid+'",'+
	    '	   "method":"showPressureChart",'+
	    '	   "version":"1.0",'+
	    '	   "requestlist":'+
	    '	   ['+
	    '	      {'+
	    '			 "befdate":"'+getLastDay(now, 15).format("yyyy-MM-dd")+'",'+
	    '			 "aftdate":"'+getNextDay(now, 15).format("yyyy-MM-dd")+'",'+
	    '			 "day":"30",'+
	    '	      }'+
	    '	   ]'+
	    '	}';

	UseAjax(urlStr, jsonStr, document.cookie, rt, '1');

};

function rt(data) {
	var systolics = new Array();
	var diastolics = new Array();
	var wi = data.resultlist[0].records;
	if(wi.length > 0){
	for (var int = 0; int < wi.length; int++) {
		var datas = wi[int].value.split("-");
		systolics[int] = [
				Date.UTC(wi[int].dates.substring(0, 4), wi[int].dates.substring(
						5, 7) - 1, wi[int].dates.substring(8, 10), wi[int].dates
						.substring(11, 13)), Number(datas[0]) ];
		diastolics[int] = [
		  				Date.UTC(wi[int].dates.substring(0, 4), wi[int].dates.substring(
		  						5, 7) - 1, wi[int].dates.substring(8, 10), wi[int].dates
		  						.substring(11, 13)), Number(datas[1]) ];
		  	
		}}
	$('#container').highcharts(
			{

				title : {
					text : ''
				},
				subtitle : {
					text :''// getLastDay(now, 15).format("yyyy-MM-dd")+" 到 "+getNextDay(now, 15).format("yyyy-MM-dd")
					
				},
				colors: ['#058DC7', '#50B432', '#ED561B', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263', '#6AF9C4'],
				xAxis : {
					 type : 'datetime',
					  dateTimeLabelFormats : {
						    second : '%H:%M:%S',
						    minute : '%H:%M',
						    hour : '%H:%M',
						    day : '%m-%d',
						    week : '%m-%d',
						    month : '%m',
						    year : '%Y'
						  }, 
					min : Date.UTC(now.getFullYear(), now.getMonth(), now
									.getDate() - 15),
					max : Date.UTC(now.getFullYear(), now.getMonth(), now
									.getDate() + 15),
					maxPadding : 5,
					gridLineWidth : 1,
					gridLineDashStyle : 'Dash',// 样式 虚线
					tickPixelInterval : 50

				},
				yAxis : {
					min : 0, // 固定列最小值
					max : 250,
					title : {
						//align: 'high',
		                //offset: 15,
		                text: 'mmHg'
		                //rotation: 0,
		                //y: 20
					},labels : {
						formatter : function() {
							return "" + this.value;
						}
					} 
					
				},
				tooltip : {
					formatter : function() {
					}
				},
				plotOptions : {
					line : {
						dataLabels : {
							enabled : true
						},
						marker: {
		                    enabled: true
		                },
						enableMouseTracking : false
					}
				},
				credits : {
					enabled : false
				},
				legend : {
					enabled : false
				},
				series : [ {
					pointPadding : 0,// 数据点之间的距离值
					groupPadding : 0,// 分组之间的距离值
					name : null,
					 name: 'systolic',
						data : systolics
					}, {
						name: 'diastolic',
						data : diastolics
				} ]
			});
}

$(function() {
	// swipe 的dome
	$("#container").swipe(
			{
				swipeLeft : function(event, direction, distance, duration,
						fingerCount) {

					now = getNextDay(now, 30);
					charts(now);
				},
				swipeRight : function(event, direction, distance, duration,
						fingerCount) {
					now = getLastDay(now, 30);
					charts(now);
				}
			});

});
